# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
	
	
	# filter - this filter routine is executed before starting the action,
	# and looks for the existence of the session
	private 					
		def check_session		
			if session[:current_user_id].nil?
				# user not logged in, redirect him to root
				flash[:notice] = "No user logged in ....!"
				redirect_to root_url
			end		
		end	
	
	def update_contact(resume)
	 	@contact 	= resume.contact
	 	contactPut 	= params[:contact]
	 	retVal = @contact.update_attributes(contactPut)
		return retVal	
	end
	
	def update_profile(resume)
		@profile 	= resume.profile
		profilePut 	= params[:profile]
		retVal = @profile.update_attributes(profilePut)
		return retVal
	end
	
	def update_skills(resume)
		@skills 	= resume.skills
		skillsPut 	= params[:skills]
		if (!skillsPut)
			return
		end
		for @skill in @skills
			retVal = @skill.update_attributes(skillsPut[@skill.id.to_s])
			if !retVal 
				break
			end			# if
		end				# for						
		return retVal	
	end
	
	def update_educations(resume)
		@educations 	= resume.educations
		educationPut 	= params[:education]
		if (!educationPut)
			return
		end
		for @education in @educations
			retVal = @education.update_attributes(educationPut[@education.id.to_s])
			if !retVal
				break
			end
		end
		return retVal
	end
	
	def update_experiences(resume)
		@experiences 	= resume.experiences
		experiencePut 	= params[:experience]
		if (!experiencePut)
			return
		end
		for @experience in @experiences
			retVal = @experience.update_attributes(experiencePut[@experience.id.to_s])
			if !retVal
				break
			end
		end	
		return retVal
	end
	
	def update_achievement(resume)
		@achievement 	= resume.achievement
		achievementPut 	= params[:achievement]
		retVal 			= @achievement.update_attributes(achievementPut)
		return retVal
	end

	def update_hobby(resume)
		@hobby 		= resume.hobby
		hobbyPut 	= params[:hobby]
		retVal 		= @hobby.update_attributes(hobbyPut)
		return retVal
	end
	
end
